<!--
 * @Author: Allen
 * @Date: 2021-01-20 11:17:56
 * @Description: 抱怨身处黑暗，不如提灯前行。愿你在自己存在的地方，成为一束光，照亮世界的一角
 * @LastEditTime: 2021-02-25 15:55:26
 * @LastEditors: Allen
 * @FilePath: \WMS\src\views\WMS\outStorageManage\loadingRecordQuery\index.vue
 * @Additional: 装车记录查询
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      v-if="initTemplate"
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsColumnDrop="true"
    >
      <template slot="controlBtn" slot-scope="scope">
        <el-link
          v-if="scope.row.PUT_COM_SIGN == 1"
          type="primary"
          class="el-icon-printer"
          :underline="false"
          @click="print(scope.row)"
          style="font-size:12px;"
        >出库单打印</el-link>
      </template>
    </one-table-template>
    <print v-if="isShow" @detailClose="detailClose" :isShow="isShow" :rowData="rowData" />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { outStockApi } from "@/api/wms/outStock";
import OneTableTemplate from "@/components/wms/templates/oneTable";
import request from "@/utils/request";
export default {
  name: "stockQuery",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate,
    print: () => import("./print")
  },
  watch: {
    $route(val) {
      if (
        this.formField.pageId !== "" &&
        this.$route.query.pageId !== undefined &&
        this.$route.query.pageId !== this.formField.pageId
      ) {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
        this.queryTable();
      }
    }
  },
  created() {
    if (this.$route.query != null) {
      // 判断传入query参数，初始化数据
      if (this.$route.query.pageId != null && this.$route.query.pageId !== "") {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
      }
    }
    this.querySelect();
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: outStockApi.queryLoadingRecord,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(),
          name: "search",
          position: "right",
          text: "查询" //"查询"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        },
          {
          compKey: "btnKey6",
          type: "",
          size: "small",
          clickEvent: () => this.export(),
          name: "export",
          position: "left",
          text: "装车记录导出", //"导出"
        },
        // {
        //   compKey: "btnKey2",
        //   type: "",
        //   size: "small",
        //   clickEvent: () => this.add(),
        //   name: "add",
        //   position: "left",
        //   text: "新增" //"导出"
        // },
        // {
        //   compKey: "btnKey4",
        //   type: "",
        //   size: "small",
        //   clickEvent: () => this.export(),
        //   name: "export",
        //   position: "left",
        //   text: "导出" //"导出"
        // }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "仓库名称", //仓库名称
          codeField: "WAREHOUSE_IDS",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: true,
          options: []
        },
        {
          compKey: "compKey2",
          labelName: "发运单号",
          codeField: "CONSIGN_ORDER_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey3",
          labelName: "装车完成标识",
          codeField: "PUT_COM_SIGN",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "inputText",
          isMust: true,
          options: [
            {
              label: "已完成",
              value: 1
            },
            {
              label: "未完成",
              value: 0
            }
          ]
        },
        {
          compKey: "compKey4",
          labelName: "车牌号",
          codeField: "CAR_NO",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey5",
          labelName: "出库去向编号",
          textField: "OUT_STORAGE_CODE",
          codeField: "OUT_STORAGE_CODE",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsDeliveryGo"),
          type: "propus",
          span: 6,
          isMust: true,
          isMul: false,
          returnCodeField: "OUT_STORAGE_CODE",
          returnTextField: "OUT_STORAGE_CODE"
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "controlBtn",
          label: "操作",
          codeField: "controlBtn",
          width: 100,
          align: "center",
          isSlot: true
        },
        {
          prop: "WAREHOUSE_NAME",
          label: "仓库名称",
          align: "center"
        },
        {
          prop: "CAR_NO",
          label: "车牌号",
          align: "center"
        },
        {
          prop: "CAR_TYPE_NAME",
          label: "发货运输车型",
          align: "center"
        },
        {
          prop: "DRI_NAME",
          label: "司机姓名",
          align: "center"
        },
        {
          prop: "DRIVER_CONNECT",
          label: "司机联系方式",
          align: "center"
        },
        {
          prop: "PUT_COM_SIGN_STR",
          label: "装车完成标识",
          align: "center"
        },
        {
          prop: "CONSIGN_ORDER_CODE",
          label: "发运单号",
          align: "center",
          width: "180"
        },
        {
          prop: "CASE_CODE",
          label: "箱号",
          align: "center",
          width: "180"
        },
        {
          prop: "OUT_STORAGE_CODE",
          label: "出库去向编号",
          align: "center"
        },
        {
          prop: "PARTNER_SHORT_NAME",
          label: "出库去向名称",
          align: "center"
        },
        {
          prop: "COST_PERSON",
          label: "领用人",
          align: "center"
        },
        {
          prop: "COST_ADD",
          label: "领用地址",
          align: "center"
        },
        {
          prop: "COST_PHONE",
          label: "领用人电话",
          align: "center"
        }
      ],
      //表单查询数据
      formField: {
        WAREHOUSE_IDS: "",
        CONSIGN_ORDER_CODE: "",
        PUT_COM_SIGN: "",
        CAR_NO: "",
        OUT_STORAGE_CODE: ""
      },
      unFormField: {},
      // 控制初始化页面
      initTemplate: false,
      // 控制打印弹窗
      isShow: false,
      rowData: {}
    };
  },
  methods: {
    //打印
    print(row) {
      this.isShow = true;
      this.rowData = row;
    },
    detailClose() {
      this.isShow = false;
    },
    querySelect() {
      request({
        url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.tableComponents[0].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
          this.formField.WAREHOUSE_IDS = res.listRow[0].WAREHOUSE_ID;
        }
        this.initTemplate = true;
        this.$nextTick(() => {
          this.queryTable();
        });
      });
    },
    // 装车记录导出
       export() {
      const exportLoading = this.$loading({
        lock: true,
        text: "正在导出...",
        // spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        fullscreen: true,
      });
      request({
        url: "/mp/wm/vl/warehouse/pack/exportLoadingRecord.do",
        method: "post",
        headers: {
          "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
          Pragma: "no-cache",
          Expires: "0",
          "Content-Type": "application/json;charset=UTF-8",
        },
        responseType: "blob",
        data: this.formField,
      })
        .then((response) => {
          exportLoading.close();
          let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
          let downloadElement = document.createElement("a");
          let href = window.URL.createObjectURL(blob); // 创建下载的链接
          downloadElement.href = href;
          downloadElement.download = "装车记录导出.xls"; // 下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); // 点击下载
          document.body.removeChild(downloadElement); // 下载完成移除元素
          window.URL.revokeObjectURL(href); // 释放掉blob对象
        })
        .catch((err) => {
          exportLoading.close();
          console.log(err);
        });
    },
    // export() {
    //   const exportLoading = this.$loading({
    //     lock: true,
    //     text: "正在导出...",
    //     // spinner: "el-icon-loading",
    //     background: "rgba(0, 0, 0, 0.7)",
    //     fullscreen: true
    //   });
    //   request({
    //     url: "/mp/wm/vl/warehouse/storage/exportStorage.do",
    //     method: "post",
    //     headers: {
    //       "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
    //       Pragma: "no-cache",
    //       Expires: "0",
    //       "Content-Type": "application/json;charset=UTF-8"
    //     },
    //     responseType: "blob",
    //     data: this.formField
    //   })
    //     .then(response => {
    //       exportLoading.close();
    //       let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
    //       let downloadElement = document.createElement("a");
    //       let href = window.URL.createObjectURL(blob); // 创建下载的链接
    //       downloadElement.href = href;
    //       downloadElement.download = "库存查询导出.xls"; // 下载后文件名
    //       document.body.appendChild(downloadElement);
    //       downloadElement.click(); // 点击下载
    //       document.body.removeChild(downloadElement); // 下载完成移除元素
    //       window.URL.revokeObjectURL(href); // 释放掉blob对象
    //     })
    //     .catch(err => {
    //       exportLoading.close();
    //       console.log(err);
    //     });
    // }
  }
};
</script>
